import Vue from 'vue'
import VueRouter from 'vue-router'

// 注册路由
Vue.use(VueRouter)
// 配置路由规则
const routes = [
    {
        path: '/index',
        name: "主页",
        component: () => import('../pages/index/index.vue'),
        meta: { title: '主页' },
        children: [
            {
                path: 'home',
                name: "首页",
                component: () => import('../pages/home/home.vue'),
                meta: {
                    title: '首页',
                }
            },
            {
                path: 'cate',
                name: "分类",
                component: () => import('../pages/cate/cate.vue'),
                meta: {
                    title: '分类',
                }
            },
            {
                path: 'shop',
                name: "购物车",
                component: () => import('../pages/shop/shop.vue'),
                meta: {
                    title: '购物车',
                    back:true
                }
            },
            {
                path: 'mine',
                name: "我的",
                component: () => import('../pages/mine/mine.vue'),
                meta: {
                    title: '我的',
                }
            },
        ]
    },
    {
        path: '/login',
        name: "登录",
        component: () => import('../pages/login/login.vue'),
        meta: {
            title: '登录',
            back: true,
            register: true
        }
    },
    {
        path: '/register',
        name: "注册",
        component: () => import('../pages/register/register.vue'),
        meta: {
            title: '注册',
            back: true,
        }
    },
    {
        path: '/list',
        name: "商品列表",
        component: () => import('../pages/list/list.vue'),
        meta: {
            title: '商品列表',
            back:true
        }

    },
    {
        path: '/detail/:id',
        name: "商品详情",
        component: () => import('../pages/detail/detail.vue'),
        meta: {
            title: '商品详情',
            back:true

        }
    },
    {
        path: '/search',
        name: "搜索",
        component: () => import('../pages/search/search.vue'),
        meta: {
            title: '搜索',
            back: true
        }
    },
 
    {
        path: "/order",
        component: () => import("../pages/order/order.vue"),
        meta: {
          title: "确认订单",
          back: true
        }
      },
      {
        path: "/pay",
        component: () => import("../pages/pay/pay.vue"),
        meta: {
          title: "订单支付",
          back: true
        }
      },
       {
        path: "/a-list",
        component: () => import("../pages/address_list/list.vue"),
        meta: {
          title: "地址管理",
          back: true
        }
      }, {
        path: "/a-add",
        component: () => import("../pages/address_add/add.vue"),
        meta: {
          title: "地址编辑",
          back: true
        }
      },
    {
        path: '/account',
        name: "支付",
        component: () => import('../pages/account/account.vue'),
        meta: {
            title: '支付页面',
            back:true
        }
    },
    
    {
        path: '*',
        redirect: '/login',
    },

]
// 路由器
const router = new VueRouter({
    mode: "hash",
    routes,
    // 滚动行为
    scrollBehavior(to, from, savePosition) {
        return savePosition ? savePosition : { x: 0, y: 0 }
    }
})

const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)}
   
// 暴露
export default router